import { graphql } from 'react-apollo';
import gql from 'graphql-tag';

export const StoragePageQuery = gql`
  query StoragePage($storeId:String,$search:String) {
    storeItems(storeId:$storeId,search:$search) {
      id
      type
      content
      location
      order {
        id
        status {
          displayStatus
        }
        shipping {
          district
        }
      }
    }
  }
`;

export const AssignFactoryQuery = gql`
  query AssignFactoryQuery($date:String!) {
    checkingOrders(date:$date) {
      orderNumber
      bags
      checkedBags
      pickupWorker
      assignedFactory
      orderStatus
      ready
      orderId
      factoryId
      displayType
      express
      business
      premium
    }
    factories(limit:100) {
      id
      name
    }
  }
`;

export const BagCheckQuery = gql`
  query BagCheckPage($date:String!) {
    checkingOrders(date:$date) {
      orderNumber
      bags
      checkedBags
      pickupWorker
      assignedFactory
      orderStatus
      ready
      orderId
      factoryId
      displayType
      express
      business
      premium
      estDate
    }
  }
`;

const OrderFragment = gql`
  fragment OrderFragment on Order {
    id
    displayId
    orderTypeDescription
    status {
      statusId
    }
    shipping {
      date
      displayDate
      unitNumber
      address
      postalCode
      contactName
      contact
    }
    pricing {
      details {
        description
        quantity
        quantityUnit
        subDescription
      }
    }
  }
`;

export const MyJobQuery = gql`
  query MyJobQuery($date:String!) {
    orders(date:$date) {
      ...OrderFragment
    }
    workingDays(date:$date)
  }
  ${OrderFragment}
`;
